import requests
from loguru import logger

from config import ENV

token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpc3MiOiIxMjQuNzAuMzkuMjAxIiwiYXVkIjoiMTI0LjcwLjM5LjIwMSIsImlhdCI6MTc0NDU5OTkyOCwibmJmIjoxNzQ0NTk5OTI4LCJleHAiOjE3NDUyMDQ3MjgsImp0aSI6IjFfYWRtaW4ifQ.RWEuwRinNSwQ3iLMtRhRf9DWKXoNrH4jDgcZ-B5zvSM"
def request_hook(response,*args,**kwargs):
    logger.debug(f"响应结果：{response.text}")

class BaseRequest:
    def __init__(self):
        self._session = requests.Session()
        self._session.headers.update({"Content-Type":"application/json","token":token})
        self._session.hooks["response"].append(request_hook)
        self._requests = self._session

    def _post(self,url,data):
        logger.debug(f"请求参数：{url}{data}")
        return self._requests.post(f"{ENV.HOST}{url}",json=data).json()

    def _get(self,url,params=None):
        logger.debug(f"请求参数：{url}{params}")
        return self._requests.get(f"{ENV.HOST}{url}",params=params).json()

    def _put(self,url,data):
        logger.debug(f"请求参数：{url}{data}")
        return self._requests.put(f"{ENV.HOST}{url}",json=data).json()

    def _delete(self,url,params=None):
        logger.debug(f"请求参数：{url}{params}")
        return self._requests.delete(f"{ENV.HOST}{url}",params=params).json()



